package com.xmb.wechat.view.alipay;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.blankj.utilcode.util.ToastUtils;
import com.xmb.wechat.R;
import com.xmb.wechat.R2;
import com.xmb.wechat.base.BaseActivity;
import com.xmb.wechat.definterface.HintListener;
import com.xmb.wechat.util.PicChooseUtils;
import com.xmb.wechat.util.PicLoadUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @Author lijiangop
 * @CreateTime 2020/5/21 09:27
 */
public class AliPayYEBActivity extends BaseActivity {

    @BindView(R2.id.et_balance)
    EditText  mEtBalance;
    @BindView(R2.id.et_yesterday_earnings)
    EditText  mEtYesterdayEarnings;
    @BindView(R2.id.et_total_earnings)
    EditText  mEtTotalEarnings;
    @BindView(R2.id.et_seven_nh)
    EditText  mEtSevenNh;
    @BindView(R2.id.iv_cover)
    ImageView mIvCover;

    private String mScreenShot;

    public AliPayYEBActivity() {
        super(R.layout.activity_alipay_yeb);
    }

    @Override
    protected void initView() {
        showExemption(new HintListener() {
            @Override
            public void onConfirm() {
                //do nothing
            }

            @Override
            public void onCancel() {
                AliPayYEBActivity.this.finish();
            }
        });
    }

    @OnClick({R2.id.ll_bg, R2.id.btn_preview})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == R.id.ll_bg) {
            PicChooseUtils.chooseOnePicWithCut(this, Pic -> showResult(Pic[0]));
        } else if (id == R.id.btn_preview) {
            if (TextUtils.isEmpty(mScreenShot)) {
                ToastUtils.showShort("请选择余额宝页面截屏");
                return;
            }
            String balance = mEtBalance.getText().toString().trim();
            if (TextUtils.isEmpty(balance)) {
                ToastUtils.showShort("请填写总金额");
                return;
            }
            String yEarnings = mEtYesterdayEarnings.getText().toString().trim();
            if (TextUtils.isEmpty(yEarnings)) {
                ToastUtils.showShort("请填写昨日收益");
                return;
            }
            String tEarnings = mEtTotalEarnings.getText().toString().trim();
            if (TextUtils.isEmpty(tEarnings)) {
                ToastUtils.showShort("请填写累计收益");
                return;
            }
            String sevenNh = mEtSevenNh.getText().toString().trim();
            if (TextUtils.isEmpty(sevenNh)) {
                ToastUtils.showShort("请填写七日年化率");
                return;
            }
            AliPayYEBDetailActivity.start(this, mScreenShot, balance, yEarnings, tEarnings, sevenNh);
        }
    }

    private void showResult(String picPath) {
        if (TextUtils.isEmpty(picPath))
            return;
        mScreenShot = picPath;
        PicLoadUtils.loadSdcardPic(picPath, mIvCover);
    }
}
